package com.ssoserver.config;

import com.ssoserver.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MyPasswordEncoder implements PasswordEncoder {
    @Autowired
    private UserService userService;

    @Override
    public String encode(CharSequence rawPassword) {
        return rawPassword.toString()+"==eilen";
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        Integer count = userService.findByPassword(rawPassword);
        log.info("rawPassword:{},encodedPassword:{}",rawPassword,encodedPassword);
        if (count >= 1){
            return true;
        }else {
            return false;
        }
        //return encode(rawPassword).equals(encodedPassword);
    }
}
